#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <unistd.h>


int init(int port, char* ip)
{
    int sockfd = socket(AF_INET, SOCK_STREAM, 0);
		if(sockfd==-1)
		return -1;
		//绑定套节字
		struct sockaddr_in addr;
		addr.sin_family = AF_INET;
   	 	addr.sin_port = htons(6666);
    	addr.sin_addr.s_addr = inet_addr(ip);
    	if (bind(sockfd, (struct sockaddr *)&addr, sizeof(addr)) == -1)
    	return -1;
		//监听套节字
		if(listen(sockfd,4)==-1)
		return -1;
		printf("等待连接\n");
		
		return sockfd;
}
